<template>
    <div>
        <h1>新增会员</h1>

        <table>
            <tbody>
                <tr>
                    <td>姓名</td>
                    <td>
                        <input type="text" v-model="data.name" >
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="data.password" >
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="保存" @click="saveinfo" >
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">

import {ref} from 'vue'
import axios from 'axios'
import {useRouter} from "vue-router" //引用 引入 

const rounter= useRouter();  //实例化

const data=ref({
  "id": 0,
  "name": "",
  "password": ""
})

const saveinfo=()=>{
    //axios.post("",{}).then(res=>{})
    if(data.value.name=="")
    {
        alert('姓名不能为空')
        return;
    }

    axios.post("https://localhost:7139/api/Member/AddMember",data.value).then(res=>{
        if(res.data>0){
            alert('新增成功')
            //跳转页面   //
            rounter.push({path:"/"})
        }
        else{
            alert('新增失败了。。。。。。')
        }
    })
}


</script>

<style scoped>

</style>